<template>
    <div class="list_page_div">
		<page-list :loading="loading" :table-config="tableConfig" :data-list="dataList" :height="height" show-index
				   show-page :total="total" :currentPage="param.pageNum" :pageSize="param.pageSize" @currentChange="handleCurrentChange"
				   show-operate operate-width="180px">
            <template #searchArea>
                <el-input v-model="param.enterpriseName" clearable placeholder="企业名称" style="width: 200px;"></el-input>
                <el-button type="primary" @click="searchList">查询</el-button>
                <el-button type="primary" @click="resetData">重置</el-button>
                <el-button type="primary" @click="editData()" v-if="powerList.indexOf('systemEnterprise:insert')>-1">新增</el-button>
            </template>
            
            <template #item_initializeFlag="scope">
                {{ $common.getDicName('yesNo', scope.row.initializeFlag) }}
            </template>

            <template #operateContent="scope">
                <el-button type="text" @click="editData(scope.row.id, scope.row.powerIdList)" v-if="powerList.indexOf('systemEnterprise:update')>-1">编辑</el-button>
                <el-popconfirm title="是否确定删除当前数据？" @confirm="delData(scope.row.id)" v-if="powerList.indexOf('systemEnterprise:delete')>-1">
                    <el-button slot="reference" type="text">删除</el-button>
                </el-popconfirm>
                <el-button type="text" @click="doInitialize(scope.row.id)" v-if="powerList.indexOf('systemEnterprise:initialize')>-1">初始化</el-button>
            </template>
        </page-list>
        <!--编辑-->
        <enterprise-edit :visible.sync="showEdit" :id="id" :select-id-list="selectIdList" @refreshList="searchList"></enterprise-edit>
	</div>
</template>

<script>
import PageList from "@/components/grid/pageList.vue";
import EnterpriseEdit from "./compnent/enterpriseEdit.vue";

export default {
    name: "enterprise",
    components: {EnterpriseEdit, PageList},
    data() {
        return {
            height: '500px',
            loading: false,
            showEdit: false,
            showSort: false,
            
            selectIdList: [],
            initializeFlag: 1,
            
            id: '',
            tableConfig: [
                {label: "企业编号", prop: "enterpriseCode", width: 300},
                {label: "企业名称", prop: "enterpriseName", minWidth: 300},
                {label: "管理员账号", prop: "accountNumber", width: 200},
                {label: "初始化", prop: "initializeFlag", width: 80, slot: true},
                {label: "创建时间", prop: "createTime", width: 200},
            ],
            dataList: [],
            total: 0,
            param: {
                enterpriseName: '',
                field: 'create_time',
                order: 'desc',
                pageSize: 20,
                pageNum: 1,
            },
            powerList: [],
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.powerList = this.$common.getPowerList("enterprise");
            this.height = (document.body.offsetHeight - 185) + "px";
        })
        this.searchList();
    },
    methods: {
        handleCurrentChange(val) {
            this.param.pageNum = val;
            this.searchList();
        },
        resetData() {
            this.param.enterpriseName = '';
            this.param.pageNum = 1;
            this.searchList();
        },
        searchList() {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/systemEnterprise/getPageList", this.param).then(res => {
                this.total = res.data.total;
                this.dataList = res.data.rows;
                this.loading = false;
            }).catch(() => {
                this.loading = false;
            })
        },
        editData(id, powerIdList) {
            this.id = id;
			this.selectIdList = powerIdList;
            this.showEdit = true;
        },
        delData(id) {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/systemEnterprise/delete/" + id).then(res => {
                this.searchList();
                this.$message.success("删除成功！");
            }).catch(() => {
                this.loading = false;
            })
        },
        doInitialize(id) {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/systemEnterprise/initialize/" + id).then(res => {
                this.searchList();
                this.$message.success("初始化成功！");
            }).catch(() => {
                this.loading = false;
            })
        },
        showSortData(childList){
            this.btnDataList = childList;
            this.showSort = true;
        },
    }
}
</script>

<style scoped>

</style>